package self.niu.com.resume;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Environment;

import com.baidu.mapapi.SDKInitializer;
import com.lidroid.xutils.DbUtils;

import self.niu.com.resume.constant.Config;
import self.niu.com.resume.initData.InitData;
import self.niu.com.resume.utils.LocationHelper;


public class AppBase extends Application {
    public static Context context;
    public static DbUtils db;
    public SharedPreferences spf;

    @Override
    public void onCreate() {
        super.onCreate();

        this.context = getApplicationContext();
        LocationHelper.init(this);
        isFrist();
    }

    public void isFrist() {
        spf = getSharedPreferences("isfrist", MODE_PRIVATE);
        if (spf.getBoolean("isfrist", true)) {
            new Thread() {
                @Override
                public void run() {
                    super.run();
                    InitData.setData();
                    InitData.setJavaDatatoDb();
                }
            }.start();
            SharedPreferences.Editor editor = spf.edit();
            editor.putBoolean("isfrist", false);
            editor.commit();
        }
    }

    public static Context getContext() {
        return context;
    }

    public static void initDbconfig() {
        DbUtils.DaoConfig config = new DbUtils.DaoConfig(context);
        db = DbUtils.create(config); //初始化db
        config.setDbDir(Environment.getExternalStorageDirectory() + Config.DB_PATH);
        config.setDbName(Config.Db_NAME);
        config.setDbVersion(Config.DB_VIERSION);
        config.setDbUpgradeListener(new DbUtils.DbUpgradeListener() {
            @Override
            public void onUpgrade(DbUtils dbUtils, int i, int i1) {
            }
        });
    }
}